package com.xiyu.service.controller.admin.unit;
import com.xiyu.service.vo.unit.worker.WorkerGetGroupRankInfoOutput;
import com.xiyu.service.vo.unit.worker.WorkerUpdateInput;
import com.xiyu.service.vo.unit.worker.WorkerPageQueryOutput;
import com.xiyu.service.vo.unit.worker.WorkerPageQueryInput;
import com.xiyu.service.vo.unit.worker.WorkerCreateInput;
import com.xiyu.service.vo.unit.worker.WorkerSingleGetOutput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.unit.WorkerService;

@Tag(name = "单位员工")
@RestController
@RequestMapping("/unit/worker")
@Validated
public class WorkerController {

    @Resource
    private WorkerService workerService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询单位职工")
    @PreAuthorize("@ss.hasPermission('unit:worker:query')")
    public CommonResult<PageResult<WorkerPageQueryOutput>> pageQuery(@Valid WorkerPageQueryInput inputVO) {
        return success(workerService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增单位职工")
    @PreAuthorize("@ss.hasPermission('unit:worker:create')")
    public CommonResult<Long> create(@Valid @RequestBody WorkerCreateInput inputVO) {
        return success(workerService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新单位职工")
    @PreAuthorize("@ss.hasPermission('unit:worker:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody WorkerUpdateInput inputVO) {
        return success(workerService.update(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个单位职工")
    @Parameter(name = "id", description = "单位职工主键ID", example = "")
    public CommonResult<WorkerSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(workerService.singleGet(id));
    }

    @GetMapping("/get-group-rank-info")
    @Operation(summary = "获取根据职级聚合信息")
    public CommonResult<List<WorkerGetGroupRankInfoOutput>> getGroupRankInfo() {
        return success(workerService.getGroupRankInfo());
    }

}
